<template>
        <!-- 地图里放个画布 -->
    <!-- ref作用：与当前dom元素关联 -->
    <div ref="parent" class="gamemap">
        <canvas ref="canvas" tabindex="0"></canvas>
    </div>

</template>

<script>
import { GameMap } from '@/assets/scripts/GameMap';
import { ref , onMounted} from 'vue';
import { useStore } from 'vuex';

export default {

    setup() {
        const store = useStore();
        let parent = ref(null);
        let canvas = ref(null);
 // 创建页面时执行该函数
        onMounted(() => {
             // 创建游戏地图，将画布与地图dom传入地图对象
            store.commit("updategameObject",
                new GameMap(canvas.value.getContext('2d'),parent.value,store)
            );

        });

        return {
            parent,
            canvas
        }
    }
}
</script>
<style scoped>

/* 地图的大小和位置 */
div.gamemap{
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}
</style>